package com.hnevc.drawerlayoutdemo;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    DrawerLayout mDrawerLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawerlayout);
        mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                //获取主界面视图
                FrameLayout view = (FrameLayout) MainActivity.this
                        .findViewById(R.id.id_main);
                //获取主界面视图的布局外边界布局参数
                ViewGroup.MarginLayoutParams marginLayoutParams
                        = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
                //修改主界面视图的布局参数，左边界与滑动控件相一致
                marginLayoutParams.setMarginStart(
                        (int)(slideOffset*drawerView.getWidth())
                        );
                //设置主界面的布局参数
                view.setLayoutParams(marginLayoutParams);
            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {

            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

    }
}
